package com.example.service;

import com.example.entity.BooksCatalogue;
import com.example.mapper.BooksCatalogueMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
书籍目录业务处理
 */
@Service
public class BooksCatalogueService {

    @Resource
    private BooksCatalogueMapper booksCatalogueMapper;

    public void add(BooksCatalogue booksCatalogue) {
        booksCatalogueMapper.insert(booksCatalogue);
    }

    public void deleteById(Integer id) {
        booksCatalogueMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            this.deleteById(id);
        }
    }

    public void updateById(BooksCatalogue booksCatalogue) {
        booksCatalogueMapper.updateById(booksCatalogue);
    }

    public BooksCatalogue selectById(Integer id) {
        return booksCatalogueMapper.selectById(id);
    }

    public List<BooksCatalogue> selectAll(BooksCatalogue booksCatalogue) {
        return booksCatalogueMapper.selectAll(booksCatalogue);
    }

    public PageInfo<BooksCatalogue> selectPage(BooksCatalogue booksCatalogue, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<BooksCatalogue> booksCatalogueList = booksCatalogueMapper.selectAll(booksCatalogue);
        return PageInfo.of(booksCatalogueList);
    }
}
